﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Work : System.Web.UI.Page
{
    private int iCameFromPage=0;
    private int iWorkType=0;
    private int iWorkID;
    protected LocalFunctions FUNC;
    protected string sBannerTitle, sTitle;
    protected string sContent;
    protected int iPrevID, iNextID;

    protected void Page_Load(object sender, EventArgs e)
    {

        FUNC = ((ArtCube)this.Master).FUNC;

        sBannerTitle = FUNC.GetPhrase(2);

        GetAttributes();
        //Load pageData
        Dal.arParams.Clear();
        Dal.arParams.Add(iWorkType);
        Dal.arParams.Add(iWorkID); // Work Type
        Dal.arParams.Add((int)((ArtCube)this.Master).FUNC.LangID); // Curent language
        DataSet DS = Dal.ExecuteDBspDS("GetWorkByID", Dal.arParams);

        // If not null - fill fields
        if (DS != null)
        // Set Article
        {
            if (DS.Tables[0].Rows.Count > 0)
            {
                DataRow Row = DS.Tables[0].Rows[0];
                try
                {
                    iPrevID = Convert.ToInt32(Row["ID"]);
                    lnkPrevWork.NavigateUrl = string.Format("work.aspx?id={0}&wt={1}&page={2}", iPrevID, iWorkType, iCameFromPage);
                }
                catch 
                {
                    divPrev.Visible = false;
                    lnkPrevWork.Visible = false;
                }
            }

            if (DS.Tables[1].Rows.Count > 0)
            {
                DataRow Row = DS.Tables[1].Rows[0];

                this.Title = sTitle = Row["Title"].ToString();
                sContent = Row["Content"].ToString();
            }

            if (DS.Tables[2].Rows.Count > 0)
            {
                DataRow Row = DS.Tables[2].Rows[0];
                try
                {
                    iNextID = Convert.ToInt32(Row["ID"]);
                    lnkNextWork.NavigateUrl = string.Format("work.aspx?id={0}&wt={1}&page={2}", iNextID, iWorkType, iCameFromPage);
                }
                catch
                {
                    divNext.Visible = false;
                    lnkNextWork.Visible = false;
                }
               
            }

            if (DS.Tables[3].Rows.Count > 0)
            {
                foreach (DataRow Row in DS.Tables[1].Rows)
                {
                    try
                    {
                        switch (Convert.ToInt32(Row["placeID"]))
                        {
                            case 1:
                                img1.Src = "content/galery/" + Row["preview"].ToString();
                                lnkImg1.HRef = "content/galery/" + Row["image"].ToString();
                                break;
                            case 2:
                                img2.Src = "content/galery/" + Row["preview"].ToString();
                                lnkImg2.HRef = "content/galery/" + Row["image"].ToString();
                                break;
                            case 3:
                                img3.Src = "content/galery/" + Row["preview"].ToString();
                                lnkImg3.HRef = "content/galery/" + Row["image"].ToString();
                                break;
                        }
                    }
                    catch { }
                }
            }
        }
        lnkBack.NavigateUrl = string.Format("portfolio.aspx?page={0}&wt={1}",iCameFromPage,iWorkType);
    }

    private void GetAttributes()
    {
        iCameFromPage=Convert.ToInt16(Request.QueryString["Page"]);
        iWorkID = Convert.ToInt16(Request.QueryString["id"]);
        iWorkType = Convert.ToInt16(Request.QueryString["wt"]);

        //hightlight submenu
        switch(iWorkType)
        {
            case 1:
                lnkIllustrator.CssClass = "btnIlustratorSelected";
                break;
            case 2:
                lnkBrand.CssClass = "btnBrandSelected";
                break;
            case 3:
                lnkAnimation.CssClass = "btnAnimationSelected";
                break;
            case 4:
                lnkPrint.CssClass = "btnPrintSelected";
                break;
            case 5:
                lnkWeb.CssClass = "btnWebSelected";
                break;
            default:
                break;
        }
    }

}


